package List;

public class PlayerNode implements Comparable<PlayerNode> {
	private int id;
	private int armySize;
	private int zeroUU;
	private int up;
	private int ascention;
	private String alliance;
	private String name;
	private boolean asgard;
	private int relation;
	private long naq;
	protected PlayerNode nextNaq;
	protected PlayerNode nextArmy;
	protected PlayerNode next;
	private boolean lock = false;

	//yet to implement planets.
	//private Vector<PlanetNode> planets = new Vector<PlanetNode>();
	
	public PlayerNode(String n, int a){
		name = n;
		armySize = a;
	}
	
	public PlayerNode clone(){
		PlayerNode temp = new PlayerNode(name, armySize);
		temp.id = id;
		temp.zeroUU = zeroUU;
		temp.up = up;
		temp.ascention = ascention;
		temp.alliance = alliance;
		temp.asgard = asgard;
		temp.relation = relation;
		temp.naq = naq;
		return temp;
	}
	
	public boolean equals(PlayerNode p){
		if((p.getName().equals(name) && (id == 0 || p.getId() == 0)) || (p.getId() == id && id != 0))
			return true;
		return false;
	}	
	
	public synchronized void lock(){
		while(lock)
		{
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {}
		}
		lock = true;
	}
	
	public synchronized void unlock() throws NodeNotLockedException{
		if(!lock)
			throw new NodeNotLockedException();
		lock = false;
	}

	@Override	
	public int compareTo(PlayerNode n){		
		return armySize - n.armySize;
	}

	public int getRelation() {
		return relation;
	}

	public void setRelation(int relation) {
		this.relation = relation;
	}

	public long getNaq() {
		return naq;
	}

	public void setNaq(long naq) {
		this.naq = naq;
	}
	
	public boolean isAsgard() {
		return asgard;
	}

	public void setAsgard(boolean asgard) {
		this.asgard = asgard;
	}

	public int getAscention() {
		return ascention;
	}

	public void setAscention(String ascention) {
		//finish this later.
		this.ascention = 0;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setId(int i) {id = i;}
	
	public int getId() {return id;}

	public int getArmySize() {return armySize;}

	public void setArmySize(int armySize) {this.armySize = armySize;}

	public int getUp() {return up;}

	public void setUp(int up) {this.up = up;}

	public String getAlliance() {return alliance;}

	public void setAlliance(String alliance) {this.alliance = alliance;}

	public int getZeroUU() {return zeroUU;}
	
	public void setZeroUU(int zeroUU){this.zeroUU = zeroUU;}
}
